import axios from '@/utils/request.js'
// 获取-所有频道列表
export const getAllChannelsAPI = () => {
  return axios({
    url: '/v1_0/channels',
    method: 'GET'
  })
}
// 登录注册接口
export const loginAPI = ({ mobile, code }) => {
  return axios({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 获取-用户选择的频道
export const getUsersChannelsAPI = () => {
  return axios({
    url: '/v1_0/user/channels',
    method: 'GET'
  })
}

// 设置-频道列表
export const setChannelsAPI = (channels) => {
  return axios({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels
    }
  })
}

// 获取-文章列表
export const getArticlesAPI = ({ channel_id, timestamp }) => {
  return axios({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      channel_id,
      timestamp
    }
  })
}

// 文章-不感兴趣
export const disArtAPI = (id) =>
  axios({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: id
    }
  })

// 文章-举报文章
export const reportArtAPI = (id, type, remark) =>
  axios({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: id,
      type: type,
      remark: remark
    }
  })

// 获取-搜索结果
export const searchAPI = (keyword) => {
  return axios({
    url: '/v1_0/suggestion',
    method: 'GET',
    params: {
      q: keyword
    }
  })
}

// 获取-搜索结果
export const searchResultAPI = ({ page = 1, per_page = 10, q }) =>
  axios({
    url: '/v1_0/search',
    method: 'GET',
    params: {
      page,
      per_page,
      q
    }
  })

// 获取-文章详情
export const articleDetailAPI = ({ article_id }) =>
  axios({
    url: `/v1_0/articles/${article_id}`,
    method: 'GET'
  })

// 文章-关注作者
export const userFollowAPI = ({ aut_id }) =>
  axios({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: aut_id
    }
  })

// 文章-取关作者
export const userUnFollowAPI = ({ aut_id }) =>
  axios({
    url: `/v1_0/user/followings/${aut_id}`,
    method: 'DELETE'
  })

// 文章-点赞
export const artLikeAPI = ({ art_id }) =>
  axios({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: art_id
    }
  })

// 文章-取消点赞
export const artDislikeAPI = ({ art_id }) => {
  axios({
    url: `/v1_0/article/likings/${art_id}`,
    method: 'DELETE'
  })
}

// 获取-文章评论列表
// 如果参数不能解构出来，且参数默认为null，那么该参数不会在拼接在请求地址后
export const getCommentsAPI = ({ article_id, offset = null, limit = 10 }) =>
  axios({
    url: '/v1_0/comments',
    method: 'GET',
    params: {
      type: 'a',
      source: article_id,
      offset,
      limit
    }
  })

// 评论-点赞
export const LikeCommentAPI = ({ com_id }) => {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: com_id
    }
  })
}

// 评论-取消点赞
export const DislikeCommentAPI = ({ com_id }) => {
  return axios({
    url: `/v1_0/comment/likings/${com_id}`,
    method: 'DELETE'
  })
}

// 增加-文章评论
export const sendCommentAPI = (id, content) =>
  axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: { target: id, content: content }
  })

// 文章-收藏
export const collectArtAPI = ({ article_id }) =>
  axios({
    url: '/v1_0/article/collections',
    method: 'POST',
    data: {
      target: article_id
    }
  })

// 文章-取消收藏
export const unCollectArtAPI = ({ article_id }) =>
  axios({
    url: `/v1_0/article/collections/${article_id}`,
    method: 'DELETE'
  })

// 获取-用户基本资料
export const getUserInfoAPI = () =>
  axios({
    url: '/v1_0/user',
    method: 'GET'
  })

// 获取-用户个人简介
export const getUserProfileAPI = () =>
  axios({
    url: '/v1_0/user/profile',
    method: 'GET'
  })

// 更新-用户个人简介
export const UserPhotoAPI = (userObj) =>
  axios({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: userObj
  })

// 更新-用户头像
export const upDataUserProfileAPI = ({ name, gender, birthday, real_name, intro }) =>
  axios({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      name,
      gender,
      birthday,
      real_name,
      intro
    }
  })

// 刷新token
export const refreshTokenAPI = () =>
  axios({
    url: '/v1_0/authorizations',
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${localStorage.getItem('refreshToken')}`
    }
  })
